package ru.tennisworld.user.controllers;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import ru.tennisworld.user.controller.TennisUserProfileController;
import ru.tennisworld.user.dto.profile.UserProfileRequestDto;
import ru.tennisworld.user.dto.profile.UserProfileResponseDto;
import ru.tennisworld.user.dto.profile.UserProfileUpdateRatingRequestDto;
import ru.tennisworld.user.entities.TennisUserProfile;
import ru.tennisworld.user.mappers.TennisUserProfileMapper;
import ru.tennisworld.user.service.TennisUserProfileControllerService;
import ru.tennisworld.user.service.users.TennisUserProfileService;

@RestController
public class TennisUserProfileControllerImpl implements TennisUserProfileController {

    @Autowired
    private TennisUserProfileControllerService tennisUserProfileControllerService;

    private static final Logger LOG = LoggerFactory.getLogger(TennisUserProfileControllerImpl.class);

    @Override
    public ResponseEntity<UserProfileResponseDto> updateUserProfile(String userProfileId, UserProfileRequestDto request) {
        LOG.info("operation=TennisUserProfileControllerImpl.updateUserProfile, action=start, request={}", request);
        UserProfileResponseDto result = tennisUserProfileControllerService.updateUserProfile(userProfileId, request);
        LOG.info("operation=TennisUserProfileControllerImpl.updateUserProfile, action=end, result={}", result);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @Override
    public void deleteUserProfile(String userProfileId) {
        LOG.info("operation=TennisUserProfileControllerImpl.deleteUserProfile, action=start, id={}", userProfileId);
        tennisUserProfileControllerService.deleteUserProfile(userProfileId);
        LOG.info("operation=TennisUserProfileControllerImpl.deleteUserProfile, action=end");
    }

    @Override
    public void updatePlayersRating(UserProfileUpdateRatingRequestDto request) {
        LOG.info("operation=TennisUserProfileControllerImpl.updatePlayersRating, action=start, request={}", request);
        tennisUserProfileControllerService.updateUserRating(request);
        LOG.info("operation=TennisUserProfileControllerImpl.updatePlayersRating, action=end");
    }
}
